package codetrainning.test3;
/*
使用递归 完成斐波那契数列的递归方式编写 并计算参数为20的时候 的值
 */
public class Demo3 {
    public static void main(String[] args){
        int result=0;
        try {
            result = sequenceFeibonacci(20);
        } catch (NumberOutOfBoundException e) {
            System.out.println("输出的数字小于2");
        }

        System.out.println(result);
    }

    private static int sequenceFeibonacci(int num) throws NumberOutOfBoundException {
        if(num == 1 || num == 2){
            return 1;
        } else if (num < 1) {
            throw new NumberOutOfBoundException();
        } else {
            return (sequenceFeibonacci(num-1)+sequenceFeibonacci(num-2));
        }
    }

}
